package com.todo.content.application.base.conf;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author azhebuxing
 * @date 2024/12/11 02:22
 * @description
 */
@Configuration
public class ContentRabbitConfig {

    public static final String CONTENT_EXCHANGE = "todoStrategy-content";
    public static final String CONTENT_EXAMINE_QUEUE = "contentExamine";
    public static final String CONTENT_STATUS_CHANGE_QUEUE = "contentStatusChange";
    public static final String CONTENT_EXAMINE_ROUTING_KEY = "contentExamine";
    public static final String CONTENT_STATUS_CHANGE_ROUTING_KEY = "contentStatusChange";

    // 声明持久化的直连交换机
    @Bean
    public DirectExchange contentExchange() {
        return ExchangeBuilder.directExchange(CONTENT_EXCHANGE)
                .durable(true) // 持久化交换机
                .delayed()
                .build();
    }

    // 声明持久化的内容审核队列
    @Bean
    public Queue contentExamine() {
        return QueueBuilder.durable(CONTENT_EXAMINE_QUEUE) // 持久化队列
                .build();
    }

    // 声明持久化的内容状态流转队列
    @Bean
    public Queue contentStatusChange() {
        return QueueBuilder.durable(CONTENT_STATUS_CHANGE_QUEUE) // 持久化队列
                .build();
    }

    // 绑定内容审核队列到交换机
    @Bean
    public Binding bindingContentExamine() {
        return BindingBuilder.bind(contentExamine())
                .to(contentExchange())
                .with(CONTENT_EXAMINE_ROUTING_KEY);
    }

    // 绑定内容状态流转队列到交换机
    @Bean
    public Binding bindingContentStatusChange() {
        return BindingBuilder.bind(contentStatusChange()) // 修正绑定队列
                .to(contentExchange())
                .with(CONTENT_STATUS_CHANGE_ROUTING_KEY);
    }
}
